package com.weitu.risk.service.impl;

import com.weitu.risk.mapper.SeriousMapper;
import com.weitu.risk.service.SeriousService;
import com.weitu.util.IDGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by fanyuting on 2017/5/11 0011.
 */
@Service
public class SeriousServiceImpl implements SeriousService {
    @Autowired
    private SeriousMapper seriousMapper;

    @Override
    public List<Map<String, Object>> queryListByParam(Map<String, Object> map) {
        return this.seriousMapper.queryListByParam(map);
    }

    @Override
    public int queryListCountByParam(Map<String, Object> map) {
        return this.seriousMapper.queryListCountByParam(map);
    }
    /**
     * 通过id查询重大评审信息
     * @param id
     * @return
     */
    public Map<String,Object> queryInfoByRecogniseDetailId(String id){
        return this.seriousMapper.queryInfoByRecogniseDetailId(id);
    }

    @Override
    public boolean addSerious(Map<String, Object> map) {
        int result = this.seriousMapper.insertSerious(map);
        if(result<1){
            return false;
        }
        return true;
    }

    @Override
    public boolean editSerious(Map<String, Object> map) {
        int result = this.seriousMapper.updateSerious(map);
        if(result<1){
            return false;
        }
        return true;
    }

    @Override
    public Map<String, Object> queryInfoById(String id) {
        return this.seriousMapper.queryInfoById(id);
    }

    @Override
    public String copySerious(String id) {
        Map<String,Object> map = this.seriousMapper.queryInfoById(id);
        String newId = IDGenerator.getId();
        map.put("id",newId);
        Object obj = map.get("copyVersion");
        if(obj!=null){
            int copyVersion = Integer.parseInt(obj.toString())+1;
            map.put("copyVersion",copyVersion);
        }
        int result = this.seriousMapper.insertSerious(map);
        if(result<1){
            return "";
        }
        return newId;
    }

    @Override
    public boolean editAppState(String id, String appState) {
        int result = this.seriousMapper.updateAppState(id,appState);
        if(result<1){
            return false;
        }
        return true;
    }
}
